package net.scdx.hotel.service.impl;

import net.scdx.hotel.entity.Hotel;
import net.scdx.hotel.mapper.HotelMapper;
import net.scdx.hotel.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class HotelServiceImpl implements HotelService {

    @Autowired
    private HotelMapper hotelMapper;

    @Override
    public List<Hotel> queryHotels(Hotel hotel, int pageIndex, int pageSize, Date checkinTime, Date checkoutTime) throws Exception {
        int rowIndex = (pageIndex - 1) * pageSize;

        List<Hotel> hotels = hotelMapper.selectHotels(hotel, rowIndex, pageSize,checkinTime,checkoutTime);

        return hotels;
    }

    @Override
    public List<Hotel> queryHotelsByDistance(Hotel hotel, int pageIndex, int pageSize, String maxLong, String minLong, String maxLat, String minLat,
                                             Date checkinTime,Date checkoutTime) throws Exception {
        int rowIndex = (pageIndex - 1) * pageSize;

        List<Hotel> hotels = hotelMapper.selectHotelsByDistance(hotel, rowIndex, pageSize, maxLong, maxLat, minLong, minLat,checkinTime, checkoutTime);

        return hotels;
    }


    @Override
    public Hotel queryHotel(Integer hotelId) throws Exception {
        Hotel hotel = hotelMapper.selectHotelById(hotelId);

        return hotel;
    }

    @Override
    public void deleteHotelById(Integer hotelId) throws Exception{
        hotelMapper.deleteByPrimaryKey(hotelId);
    }

    @Override
    public List<Hotel> hotelsInfo(Integer adminId) throws  Exception{
        List<Hotel> hotels = hotelMapper.selectHotelsByAdminId(adminId);
        return  hotels;
    }

    @Override
    public void updateHotel(Hotel hotel) throws  Exception{
        hotelMapper.updateAllInfo(hotel);
    }

    @Override
    public int addHotel(Hotel hotel) throws  Exception{
        return hotelMapper.addHotel(hotel);
    }
}
